#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
import shutil

#操作逻辑
#1.修改payTypeConfig.xml
#2.修改ServerControl.xml

gamedir = "E:/gamecopy"
backupdir = "E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2/temp"

#检查资源相关的目录是否存在
def checkDirExist():
	if(False == os.path.exists(gamedir)):
		print( gamedir + " is not exist")
		raise( gamedir + " is not exist")
	if(False == os.path.exists(backupdir)):
		print( backupdir + " is not exist")
		raise( backupdir + " is not exist")
		
#copy文件
def copyFileSafety(backupfile,desfile):
	if( True == os.path.exists(backupfile) ):
		if( True == os.path.exists(desfile) ):
			os.remove(desfile)
		shutil.copyfile(backupfile,desfile)

#调整资源
def channelCustomOperBegin():
	print("begin , this is vivo !")
	checkDirExist()
	
	gamePayTypeConfigFile = gamedir + "/assets/soulgame/payTypeConfig.xml"
	gameServerControlFile = gamedir + "/assets/soulgame/ServerControl.xml"
	vivoPayTypeConfigFile = backupdir + "/vivo/vivo_payTypeConfig.xml"
	vivoServerControlFile = backupdir + "/vivo/vivo_ServerControl.xml"
	
	copyFileSafety(vivoPayTypeConfigFile,gamePayTypeConfigFile)
	copyFileSafety(vivoServerControlFile,gameServerControlFile)

#恢复资源
def channelCustomOperEnd():
	print("end , this is vivo !")
	checkDirExist()

if __name__=="__main__":
	if(sys.argv[1] == "begin"):
		channelCustomOperBegin()
	elif(sys.argv[1] == "end"):
		channelCustomOperEnd()
	else:
		raise("call channel custom operation must with param begin or end!")

#	channelCustomOperBegin()
#	channelCustomOperEnd()
